package com.wk1un2.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wk1un2.service.CarouselService;
import com.wk1un2.util.Result;
//轮播图控制器
@Controller
public class CarouselController {
	@Autowired
	CarouselService service;

	@RequestMapping("/Backstage/getAllCarousel")
	@ResponseBody
	public Object getAll(@RequestParam("page") int page, @RequestParam("limit") int limit,
			@RequestParam("c_name") String c_name) {

		if (c_name == null || c_name == "") {
			c_name = null;
		}
		List<Map<String, Object>> ls = service.getAll((page - 1) * limit, limit, c_name);
		Result res = new Result(0, "", service.count(), ls);
		return res;
	}

//	
	@RequestMapping("/Backstage/addCarousel")
	@ResponseBody
	public Object add(@RequestParam Map<String, Object> map) {

		System.out.println(map.get("c_name"));
		int i = service.add(map);
		Result res = new Result(0, "", i, i);
		return res;
	}

//	޸
	@RequestMapping("/Backstage/updateCarousel")
	@ResponseBody
	public Object update(@RequestParam Map<String, Object> map) {
		System.out.println(map.get("c_name"));
		int i = service.update(map);
		Result res = new Result(0, "", i, i);
		return res;
	}

//	ɾ
	@RequestMapping("/Backstage/deleteCarousel")
	@ResponseBody
	public Object delete(@RequestParam("c_id") int c_id) {
		System.out.println(c_id);
		int i = service.delete(c_id);
		Result res = new Result(0, "", i, i);
		return res;
	}
}
